package me.zhengjie.utils;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class bbb {

    /**
     * 背景图片
     * @return
     */
    public static BufferedImage getBackground(){
        //开始构造背景图片
        int width = 1000;
        int height = 1000;
        // 创建一个BufferedImage对象
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = image.createGraphics();
        // 设置渐变颜色
        Color startColor = new Color(244, 237, 233); // 浅橙色
        Color endColor = new Color(234, 186, 138);   // 深橙色
        // 创建渐变画笔
        GradientPaint gradient = new GradientPaint(0, 0, startColor,width / 2, height / 2, endColor,true);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setPaint(gradient);
        g2d.fillRect(0, 0, width, height);
        // 添加对称效果
        g2d.drawLine(0, height / 2, width, height / 2);
        g2d.drawLine(width / 2, 0, width / 2, height);
        // 释放资源
        g2d.dispose();
        return image;
    }

    /**
     * 圆环
     * @return
     */
    public static BufferedImage getRing(){
        // 创建一个透明背景的图片
        int width = 800;
        int height = 800;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = image.createGraphics();
        // 设置抗锯齿以提高图像质量
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        // 设置渐变颜色
        Color startColor = new Color(255, 255, 240); // 浅橙色
        Color endColor = new Color(246, 208, 194);
        // 设置透明颜色
        GradientPaint gradient = new GradientPaint(0, 0, startColor,width / 2, height / 2, endColor,true);
        g2d.setPaint(gradient);
        // 画外圆
        int xCenter = width / 2;
        int yCenter = height / 2;
        int outerRadius = 400; // 外半径
        int innerRadius = 380; // 内半径
        g2d.fillOval(xCenter - outerRadius, yCenter - outerRadius, 2 * outerRadius, 2 * outerRadius);
        // 设置透明色，用于绘制内圆
        g2d.setComposite(AlphaComposite.Clear);
        g2d.fillOval(xCenter - innerRadius, yCenter - innerRadius, 2 * innerRadius, 2 * innerRadius);
        g2d.setComposite(AlphaComposite.SrcOver);
        g2d.dispose();
        return image;
    }

    public  static  void main(String[] args) throws IOException {
        BufferedImage bgImg = getBackground();
        BufferedImage ringImg = getRing();
        //图片输出路径
        File outfiels = new File("D:\\360Downloads\\ttt1.jpg");

        Graphics2D g = bgImg.createGraphics();
        g.drawImage(ringImg,100,100,800,800, null);
        ImageIO.write(bgImg, "png", outfiels);
    }
}
